<html>
  <head>
    <meta charset="utf-8" />
	<title></title>
	<script>
	  //封装就是把一些功能，给放到一个函数里去整体的执行，需要的时候，调用函数
	  // 新建 添加 修改 一个cookie 
	  // 获取 
	  // 删除 
	  function setCookies(key,value,iDays){
	    //iDays 是一个数字
		var day= new Date();
		day.setDate(day.getDate()+iDays);
		//  user=abc;expires=day
		document.cookie= key+ "="+ value+";expires="+day;
	  }
	  // setCookies("username","许仙",10000);
	  // setCookies("password","123456",3);
	  // setCookies("address","HangZhou",10000);
	  document.write(document.cookie);
	  //username=许仙; password=123456; address=HangZhou 
	  // alert(document.cookie.username );
	  function getCookie(key){
	    var str = document.cookie;  //username=许仙; password=123456; address=HangZhou
		var arr = str.split("; ");
		// arr = ["username=许仙","password=123456","address=HangZhou" ]
		for(var i=0;i<arr.length;i++){
		  var arr2= arr[i].split("=");  //i=0  ["usrename" ,"许仙"]
		  if(key==arr2[0]){
		    return arr2[1]
		  }
		}
		return "";
	  }
	  // alert(getCookie("gender"));
	  
	  function removeCookie(key){
	    setCookies(key,"",-1);
	  }
	  alert(getCookie("username"));
	  removeCookie("username");
	  alert(getCookie("username"));
	</script>
  </head>
  <body></body>
</html>